package tongxunlu;

import java.util.ArrayList;
import java.util.Collections;
import java.util.TreeSet;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author Administrator
 */
public class function extends person {

    public function() {
        super();
    }

    public int Modification(ArrayList a, String s) {//查找下标；
        int k = -1;
        ArrayList ar = new ArrayList();
        ar = a;
        for (int i = 0; i < ar.size(); i++) {
            if (((person) ar.get(i)).getNAME().equals(s)) {
                k = i;
            }

        }
        return k;
    }

    public String[] Modification(ArrayList a, int k) {
        String[] strb = new String[27];
        int i = k;
        strb[0] = ( MainMenu.personList.get(i)).getNAME();
        strb[1] = ( MainMenu.personList.get(i)).getTEL();
        strb[2] = ( MainMenu.personList.get(i)).getEMAIL();
        strb[3] = (MainMenu.personList.get(i)).getBIR();
        strb[4] = ( MainMenu.personList.get(i)).getGROUP();
        strb[5] = ( MainMenu.personList.get(i)).getREMARKS();
        strb[6] = ( MainMenu.personList.get(i)).getPHOTOADD();
        strb[7] = ( MainMenu.personList.get(i)).getWORKMASSAGE().getWORKCOUNTRY();
        strb[8] = ( MainMenu.personList.get(i)).getWORKMASSAGE().getWORKPROVINCE();
        strb[9] = ( MainMenu.personList.get(i)).getWORKMASSAGE().getWORKCITY();
        strb[10] = ( MainMenu.personList.get(i)).getWORKMASSAGE().getWORKADD();
        strb[11] = ( MainMenu.personList.get(i)).getWORKMASSAGE().getWORKUNIT();
        strb[12] = ( MainMenu.personList.get(i)).getWORKMASSAGE().getDEPARTMENT();
        strb[13] = ( MainMenu.personList.get(i)).getWORKMASSAGE().getPOSITION();
        strb[14] = ( MainMenu.personList.get(i)).getWORKMASSAGE().getWORKZIPCODE();
        strb[15] = ( MainMenu.personList.get(i)).getWORKMASSAGE().getWORKTEL();
        strb[16] = ( MainMenu.personList.get(i)).getWORKMASSAGE().getWORKFAX();
        strb[17] = ( MainMenu.personList.get(i)).getNETMASSAGE().getHOMEPAGE();
        strb[18] = ( MainMenu.personList.get(i)).getNETMASSAGE().getQQNUM();
        strb[19] = ( MainMenu.personList.get(i)).getNETMASSAGE().getMSNNUM();
        strb[20] = ( MainMenu.personList.get(i)).getNETMASSAGE().getBACKUPEMAIL();
        strb[21] = ( MainMenu.personList.get(i)).getHOMEMASSAGE().getHOMECOUNTRY();
        strb[22] = ( MainMenu.personList.get(i)).getHOMEMASSAGE().getHOMEPROVINCE();
        strb[23] = ( MainMenu.personList.get(i)).getHOMEMASSAGE().getHOMECITY();
        strb[24] = ( MainMenu.personList.get(i)).getHOMEMASSAGE().getHOMEADD();
        strb[25] = ( MainMenu.personList.get(i)).getHOMEMASSAGE().getHOMEZIPCODE();
        strb[26] = ( MainMenu.personList.get(i)).getHOMEMASSAGE().getHOMETEL();
        return strb;
    }

    public ArrayList Modification(ArrayList a, person p, int m) {//修改
        ArrayList ar = new ArrayList();
        ar = a;
        ar.set(m, p);//用新的对象代替第m个元素；
        return ar;
    }

    public boolean Same(ArrayList a, person p) {//显示是否有同名或者是同电话号码的；
        ArrayList k = new ArrayList();
        k = a;
        for (int i = 0; i < k.size(); i++) {
            if (((person) k.get(i)).getNAME().equals(p.getNAME()) || ((person) k.get(i)).getTEL().equals(p.getTEL())) {
                return true;
            }
        }
        return false;

    }

    public ArrayList mohusearch(ArrayList<person> a, String s) {//模糊搜索
        String k;
        ArrayList list = new ArrayList();
        ArrayList nlist = new ArrayList();
        list = a;
        k = s;
        for (int i = 0; i < list.size(); i++) {

            if ((((person) (list.get(i))).getNAME().contains(k) || ((person) (list.get(i))).getTEL().contains(k) || ((person) (list.get(i))).getHOMEMASSAGE().getHOMETEL().contains(k)) == true) {
                nlist.add(list.get(i));//实现按姓名，手机，家庭电话查询；
            }

        }
        return nlist;//返回搜索到的list
    }

    public ArrayList Del(ArrayList a, String s) {//删除，传一个人的姓名
        ArrayList ar = new ArrayList();
        ar = a;
        if (ar.isEmpty() == true) {
            return ar;
        }
        for (int i = 0; i < ar.size(); i++) {
            if (((person) ar.get(i)).getNAME().equals(s)) {
                ar.remove(i);
            }
        }
        Collections.sort(ar, new SpellComparator());
        return ar;
    }

    public ArrayList addperson(ArrayList a, person m) {//增加一个人
        //ArrayList list=new ArrayList();
        //list=a;
        a.add(m);//���
        Collections.sort(a, new SpellComparator());
        //a=list;//����������
        return a;
    }

    public String[] divgroup(ArrayList a) {
        TreeSet<String> tr = new TreeSet<String>();
        String[] group = new String[a.size()];
        for (int i = 0; i < a.size(); i++) {
            group[i] = ((person) a.get(i)).getGROUP();
            tr.add(group[i]);
        }
        for (int i = 0; i < group.length; i++) {
            group[i] = tr.pollFirst();

        }
        return group;
    }

    public ArrayList divgroup2(ArrayList<person> a, String s) {
        ArrayList<person> ay = new ArrayList<person>();
        for (int i = 0; i < a.size(); i++) {
            if (((person) a.get(i)).getGROUP().equals(s)) {
                ay.add(a.get(i));
            }
        }
        return ay;
    }
    public int March(ArrayList<person> a,person p){
        int flag=-1;
        for(int i=0;i<a.size();i++){
            if(a.get(i).getNAME().equals(p.getNAME()) && a.get(i).getTEL().equals(p.getTEL()) && a.get(i).getBIR().equals(p.getBIR()) && a.get(i).getGROUP().equals(p.getGROUP()) &&a.get(i).getEMAIL().equals(p.getEMAIL()))
                return i;
        }
        return flag;
    }
}
